package com.luozongyao.eduService.controller;


import com.luozongyao.commonutils.R;
import com.luozongyao.eduService.entity.EduChapter;
import com.luozongyao.eduService.entity.chapter.ChapterVo;
import com.luozongyao.eduService.entity.vo.CourseInfoVo;
import com.luozongyao.eduService.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-08-11
 */
@RestController
@RequestMapping("/eduService/edu-chapter")
@CrossOrigin
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;
    //课程大纲列表，根据课程ID进行查询
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable String courseId){
        List<ChapterVo> list =chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("allChapterVideo",list);
    }


    //添加章节信息
    @PostMapping("addChapterInfo")
    public R addChapterInfo(@RequestBody EduChapter eduChapter){
        chapterService.save(eduChapter);
        return R.ok();
    }

    //根据id查询章节
    @GetMapping("getChapterInfoById/{chapterId}")
    public R getChapterInfoById(@PathVariable String chapterId){
        EduChapter chapter = chapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);
    }

    //修改章节信息
    @PostMapping("updateChapterInfo")
    public R updateChapterInfo(@RequestBody EduChapter eduChapter){
        chapterService.updateById(eduChapter);
        return R.ok();
    }

    //删除章节信息
    @DeleteMapping("deleteChapterInfoById/{chapterId}")
    public R deleteChapterInfoById(@PathVariable String chapterId){
        boolean flag=chapterService.deleteChapter(chapterId);
        if (flag){
            return R.ok();
        }else {
            return R.error();
        }
    }




}

